package com.catt.orderdinner.repository;
import com.catt.orderdinner.dataobject.OrderDetail;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface OrderDetailRepository extends JpaRepository<OrderDetail, String>{
    List<OrderDetail> findByOrderId(String orderId);

    @Query(value = "SELECT FOOD_NAME as foodName,SUM(FOOD_QUANTITY) as foodQuantity FROM order_detail WHERE UPDATE_TIME BETWEEN ?1 AND ?2 GROUP BY FOOD_NAME",
            countQuery="SELECT COUNT(DISTINCT FOOD_NAME) FROM order_detail WHERE UPDATE_TIME BETWEEN ?1 AND ?2",
            nativeQuery = true)
    Page<List<Map>> getNowOrder(Date star, Date end, Pageable pageable);
}
